package com.hframe.plugin.ronglian;

import org.apache.log4j.Logger;

import java.util.HashMap;

public class RongLianVerify {
	static Logger log = Logger.getLogger(RongLianVerify.class);
	private RongLianConfig config = null;

	public RongLianVerify(RongLianConfig config) {
		this.config = config;
	}

	/**
	 * 发送短信验证
	 * 
	 * @param code
	 *            验证码
	 * @param phone
	 *            发送的手机号
	 * @param AFI
	 *            应用标识，用于在同一个应用中使用不同验证码的标识
	 */
	public boolean sendSMS(String code, String phone, String AFI) {
		HashMap<String, Object> result = null;

//		// 初始化SDK
//		CCPRestSmsSDK restAPI = new CCPRestSmsSDK();
//		restAPI.init(config.getURL(), config.getPort());
//		restAPI.setAccount(config.getSID(), config.getToken());
//		restAPI.setAppId(config.getAppID());
//		mResult = restAPI.sendTemplateSMS(phone, config.getSMST(AFI), new String[] { code, "" + config.getPeriod() });

		if ("000000".equals(result.get("statusCode"))) {
			return true;
		} else {
			log.error("ErrorCode=" + result.get("statusCode") + " ErrorInfo= " + result.get("statusMsg"));
			return false;
		}
	}

	/**
	 * 发送语言验证
	 * 
	 * @param code
	 *            验证码
	 * @param phone
	 *            发送的手机号
	 */
	public boolean sendSpeech(String code, String phone) {
		HashMap<String, Object> result = null;

//		// 初始化SDK
//		CCPRestSDK restAPI = new CCPRestSDK();
//		restAPI.init(config.getURL(), config.getPort());
//		restAPI.setAccount(config.getSID(), config.getToken());
//		restAPI.setAppId(config.getAppID());
//		mResult = restAPI.voiceVerify(code, phone, config.getSpeechPhone(), config.getSpeechCount(), "", "", "", "", "");

		if ("000000".equals(result.get("statusCode"))) {
			return true;
		} else {
			log.error("ErrorCode=" + result.get("statusCode") + " ErrorInfo= " + result.get("statusMsg"));
			return false;
		}
	}
}
